#!perl -n

push @a, split;

END {
    for $a (1..9) {
        for $b (1..9) {
            for $c (1..9) {
                for $d (1..9) {
                    @b = ($a + $b, $c + $d, $a + $c, $b + $d, $a + $d, $b + $c);
                    if ("@a" eq "@b") {
                        print "$a $b\n$c $d";
                        exit;
                    }
                }
            }
        }
    }
    print -1;
}
